package com.zhangyusheng.easyecharts.option;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.annotation.JSONField;
import com.zhangyusheng.easyecharts.component.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * TODO：核心模型类，基础选项
 *  参考文档 https://echarts.apache.org/zh/option.html
 * @author Michael zhang
 * @email zhangys_0217@sina.com
 * @since 2025/11/3 22:32
 */
@Data
@Accessors(chain = true)
public class EChartsOption implements Serializable {
    private final static long serialVersionUID = 2L;

    private List<String> color;

    private Title title;
    @JSONField(name = "xAxis")
    private XAxis xAxis;
    @JSONField(name = "yAxis")
    private YAxis yAxis;
    private List<Series> series;
    private Grid grid;
    private Tooltip tooltip;

    public static class Builder {
        private List<String> color;
        private Title title;
        private XAxis xAxis;
        private YAxis yAxis;
        private List<Series> series;
        private Grid grid;
        private Tooltip tooltip;



        public Builder color(List<String> color) {
            this.color = color;
            return this;
        }
        public Builder title(Title title) {
            this.title = title;
            return this;
        }
        public Builder xAxis(XAxis xAxis) {
            this.xAxis = xAxis;
            return this;
        }
        public Builder yAxis(YAxis yAxis) {
            this.yAxis = yAxis;
            return this;
        }
        public Builder series(List<Series> series) {
            this.series = series;
            return this;
        }
        public Builder grid(Grid grid) {
            this.grid = grid;
            return this;
        }
        public Builder tooltip(Tooltip tooltip) {
            this.tooltip = tooltip;
            return this;
        }
        public EChartsOption build() {
            return new EChartsOption(this);
        }
    }
    private EChartsOption(Builder builder) {
        this.color = builder.color;
        this.title = builder.title;
        this.xAxis = builder.xAxis;
        this.yAxis = builder.yAxis;
        this.series = builder.series;
        this.grid = builder.grid;
        this.tooltip = builder.tooltip;
    }

    /**
     * 将当前 EChartsOption 对象转换为 JSON 字符串
     * @return JSON 格式的字符串表示
     */
    public String toJson() {
        String jsonStr = String.format("%s%s","option=", JSONObject.toJSONString(this));
        return jsonStr;
    }
}
